package service

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
)

// 保存用户数据
func (cs *Consumer) SaveData(user Consumer) {
	data, _ := json.Marshal(user)
	writeFileName := fmt.Sprintf("db/%s.json", user.Name)
	ioutil.WriteFile(writeFileName, data, 0666)
}

// 读取用户数据
func (cs *Consumer) ReadData(username string) Consumer {

	readFileName := fmt.Sprintf("db/%s.json", username)
	var data Consumer
	tmp, _ := ioutil.ReadFile(readFileName)
	json.Unmarshal(tmp, &data)
	return data
}
